package community.hospital.entity.response;


import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import community.hospital.entity.Menu;
import community.hospital.entity.Role;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author：ydj
 * @Date：2023/1/16 21:41
 */
@Data
public class UserResponse implements Serializable {
    private static final long serialVersionUID = -5642582969725624695L;
    private Long id;
    private String account;
    private String username;
    private String idCard;
    private String avatar;
    private Date gmtCreate;
    private String phone;
    private Integer state;
    private Role role;
    private List<Menu> menu;
    private Long roleId;

    /**
     * @JsonIgnore
     * 序列化的时候防止roleCode序列化为属性
     */
    @JsonIgnore
    public String getRoleCode() {
        return role==null?null:role.getRoleCode();
    }
    @JsonIgnore
    public List<String> getMenuKey() {
        return menu==null? new ArrayList<>():menu.stream().map(Menu::getMenuKey).collect(Collectors.toList());
    }
}
